package cn.tedu.ivos.geofence.controller;

import cn.tedu.ivos.base.handler.JsonResult;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceQueryParam;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceSaveParam;
import cn.tedu.ivos.geofence.pojo.entity.Geofence;
import cn.tedu.ivos.geofence.pojo.vo.GeofenceVO;
import cn.tedu.ivos.geofence.service.GeofenceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "围栏管理")
@RestController
@RequestMapping("/v1/geofence")
public class GeofenceController {

    @Autowired
    private GeofenceService geofenceService;
    @ApiOperation(value = "查询围栏信息")
    //@ApiImplicitParam(value = "查询条件", name = "geofenceQuery",required = true)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "围栏编号", name = "id",required = false),
            @ApiImplicitParam(value = "围栏名称", name = "name",required = false),
            @ApiImplicitParam(value = "围栏状态", name = "status",required = false)
    })
    @GetMapping("/select")
    public JsonResult selectGeofence(GeofenceQueryParam geofenceQuery)
    {
        List<GeofenceVO> list = geofenceService.selectGeofence(geofenceQuery);
        return new JsonResult(list);
    }

    @ApiOperation("保存围栏")
    @ApiImplicitParam(value = "围栏信息", name = "geofenceSaveParam",required = true)
    @PostMapping("/save")
    public JsonResult saveGeofence(GeofenceSaveParam geofenceSaveParam){
        geofenceService.insertGeofence(geofenceSaveParam);
        return JsonResult.ok();
    }
    @ApiOperation("删除围栏")
    @ApiImplicitParam(value = "围栏编号", name = "id",required = true)
    @DeleteMapping("/delete/{id}")
    public JsonResult deleteGeofence(@PathVariable Long id){
        geofenceService.deleteById(id);
        return JsonResult.ok();
    }
}
